//
//  BQYLRightTableViewCell.m
//  BeeQuick
//
//  Created by 杨雷 on 2016/11/19.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "BQYLRightTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface BQYLRightTableViewCell ()<BQYLAddViewDelegate>

@end



@implementation BQYLRightTableViewCell

- (void)setModel:(BQHomeGoodModel *)model
{
    _model = model;
    self.nameLabel.text = model.name;
    self.specificsLabel.text = model.specifics;
    self.priceLabel.text = model.price;
    self.market_priceLabel.text = model.market_price;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img]];
    self.buyOneView.image = [UIImage imageNamed:@"buyOne.png"];
    self.had_pm = model.had_pm.intValue;
    if (self.had_pm == 0)
    {
        self.buyOneView.hidden = YES;
    }
    else
    {
        self.buyOneView.hidden = NO;
    }
    
    _minusAddView.minusCount = model.buyCount;
    
    _minusAddView.model = model;
    
}



//加减View的代理方法
-(void)minusAddView:(BQYLAddView *)minusV withcount:(NSInteger)minusCount
{
    _model.buyCount = minusCount;
    
    if (minusV.isAdd)
    {
        UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
        
        CGPoint picPoint = [self convertPoint:self.iconView.center toView:keyWindow];
        
        if ([_delegate respondsToSelector:@selector(rightCell:withAddModel:withStartPoint:)])
        {
            [_delegate rightCell:self withAddModel:_model withStartPoint:picPoint];
        }
    }
    else
    {
        if ([_delegate respondsToSelector:@selector(rightCell:withMinusModel:)])
        {
            [_delegate rightCell:self withMinusModel:_model];
        }
    }
}


//添加加减View
- (void)awakeFromNib {
    [super awakeFromNib];
    self.contentView.backgroundColor = [UIColor whiteColor];
    //加减按钮
    BQYLAddView *minusAddView = [BQYLAddView minusAddView];
    //MARK: - 传一个模型给 这个加减号的View.

    [self.contentView addSubview:minusAddView];
    
    self.minusAddView = minusAddView;
    
    minusAddView.delegate = self;
    
    [minusAddView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-10);
        
        make.bottom.equalTo(self.contentView).offset(-10);
        
        make.size.mas_equalTo(minusAddView.bounds.size);
    }];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
